package com.jcl.recruit.attach.mapper;

import com.jcl.recruit.attach.model.UploadFileInfo;
import org.springframework.util.StringUtils;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @ClassName UploadFileProvider
 * @Description TODO
 * @Author yyliu
 * @Date 2018/10/24 13:33
 * @Version 1.0
 **/
public class UploadFileProvider {

    public String insertProvider(UploadFileInfo uploadFileInfo){
        BEGIN();
        INSERT_INTO("upload_file_info");
        if(null != uploadFileInfo.getId()){
            VALUES("id", "#{id,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getOwnerId()){
            VALUES("owner_id", "#{ownerId,jdbcType=INTEGER}");
        }
        if(StringUtils.hasLength(uploadFileInfo.getCorpCode())){
            VALUES("corp_code", "#{corpCode,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getFileName()){
            VALUES("file_name", "#{fileName,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getFilePath()){
            VALUES("file_path", "#{filePath,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getMimetype()){
            VALUES("mimetype", "#{mimetype,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getFileType()){
            VALUES("file_type", "#{fileType,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getExternalName()){
            VALUES("external_name", "#{externalName,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getCategory()){
            VALUES("category", "#{category,jdbcType=INTEGER}");
        }
        if(null != uploadFileInfo.getCreateTime()){
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        if(null != uploadFileInfo.getModifyTime()){
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }
        return SQL();
    }

    public String updateProvider(UploadFileInfo uploadFileInfo){
        BEGIN();
        UPDATE("upload_file_info");
        if(null != uploadFileInfo.getOwnerId()){
            SET("owner_id=#{ownerId,jdbcType=INTEGER}");
        }
        if(StringUtils.hasLength(uploadFileInfo.getCorpCode())){
            SET("corp_code=#{corpCode,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getFileName()){
            SET("file_name=#{fileName,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getFilePath()){
            SET("file_path=#{filePath,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getMimetype()){
            SET("mimetype=#{mimetype,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getFileType()){
            SET("file_type=#{fileType,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getExternalName()){
            SET("external_name=#{externalName,jdbcType=VARCHAR}");
        }
        if(null != uploadFileInfo.getCategory()){
            SET("category=#{category,jdbcType=INTEGER}");
        }
        if(null != uploadFileInfo.getCreateTime()){
            SET("create_time=#{createTime,jdbcType=TIMESTAMP}");
        }
        if(null != uploadFileInfo.getModifyTime()){
            SET("modify_time=#{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=VARCHAR}");
        return SQL();
    }
}
